// ----------------------------------
// RSDK Project: Sonic 1 Forever X Doki Doki Literature Club
// Script Description: Menu Control
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 1 : TYPE_SEGA
private alias 75 : SPACING_VALUE

private alias object.value0 : object.timer
private alias object.value1 : object.scrollDelayUp
private alias object.value2 : object.scrollDelayDown
private alias object.value3 : object.currentSelection
private alias object.value4 : object.drawPos.x
private alias object.value5 : object.drawPos.y
private alias object.value6 : object.stringLength
private alias object.value7 : object.letterID
private alias object.value8 : object.index
private alias object.value9 : object.secondSelection
private alias object.value10 : row.highlight
private alias object.value11 : column.highlight
private alias object.value12 : object.summonWindow
private alias object.value13 : object.touchDelay
private alias object.value14 : object.fontSize
private alias object.value15 : object.GameModesY
private alias object.value16 : object.bgBoxSize.x
private alias object.value17 : object.bgBoxSize.y
private alias object.value18 : object.windowAlpha
private alias object.value19 : object.textCenterIt
private alias object.value20 : object.charHighlight
private alias object.value21 : object.charFrameX
private alias object.value22 : object.scrollAchieveY

public value modcount = 0;
private value achieveY = 0;
private value loading = 0;
private value MenufadeColor = 0;
private value selfAware = 0;
public value optionCheck = 0;
public value deleteCheck = 0;

private alias 0 : FONT_SMALL
private alias 1 : FONT_LARGE
private alias 2 : FONT_TINY
private alias 8 : BOX_OFFSET

// Function declarations

private table MenuControl_LetterWidth
	10, 9, 10, 10, 8, 8, 11, 9, 4, 9, 10, 7, 12, 10, 11, 9, 11, 9, 9, 9, 10, 10, 15, 9, 9, 9, 
	9, 9, 9, 8, 9, 9, 8, 8, 8, 5, 7, 8, 6, 11, 8, 8, 8, 8, 7, 7, 7, 9, 7, 11, 8, 9, 7
end table

private table MenuControl_LetterWidthLarge
	19, 15, 18, 18, 15, 14, 19, 16, 7, 14, 16, 13, 21, 19, 20, 16, 20, 15, 15, 17, 17, 19, 27, 18, 18, 16     
end table

private table MenuControl_RandomCharacters
	6 // Space
	0 // @
	4 // . and !
	1 // tiny randos
end table

private table MenuControl_TinyLetterWidth
	4, 3, 4, 4, 3, 3, 4, 4, 3, 3, 3, 3, 5, 4, 4, 3, 5, 3, 3, 3, 4, 5, 5, 3, 3, 3 // upper
	4, 3, 3, 3, 3, 2, 3, 3, 1, 3, 3, 1, 5, 3, 3, 3, 4, 2, 3, 3, 3, 3, 5, 3, 3, 3 // lower
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3 // numbers
end table

private table AchieveEarned
	400, 405, 401, 402, 403, 415, 408, 404, 406, 416, 407, 409, 414, 410, 411, 418, 419, 420, 421
end table

private table ExtrasTimes
	650, 651, 0
end table

private table ExtrasUnlock
	408, 410, 0, 0
end table

private table MenuControl_LetterWidthNumbers
	10, 6, 9, 9, 9, 9, 9, 9, 9, 9
end table

reserve function SetTextFileLanguage

function SetTextFileLanguage
	switch saved.language
		default //English
			LoadTextFile(2, "Data/Game/DDLCen.txt")
			LoadTextFile(22, "Data/Game/WarningEN.txt")
			break
		case 1 //Portuguese
			LoadTextFile(2, "Data/Game/DDLCpr.txt")
			LoadTextFile(22, "Data/Game/WarningPR.txt")
			break
		case 2 //Spanish
			LoadTextFile(2, "Data/Game/DDLCsp.txt")
			LoadTextFile(22, "Data/Game/WarningSP.txt")
			break
		case 3 //French
			LoadTextFile(2, "Data/Game/DDLCfr.txt")
			LoadTextFile(22, "Data/Game/WarningFR.txt")
			break
	end switch	
end function

function DrawTimeExtra
	temp0 = object.drawPos.x
	GetTableValue(arrayPos0, temp1, ExtrasTimes)
	
	arrayPos1 = saveRAM[arrayPos0]
	arrayPos2 = 0
	arrayPos3 = 0
	
	while arrayPos1 >= 100
		arrayPos1 -= 100
		arrayPos2++
	loop
	
	while arrayPos2 >= 60
		arrayPos2 -= 60
		arrayPos3++
	loop

	if temp2 == temp6
		CopyPalette(0, 149, 0, 50, 1)
	end if

	temp7 = 0
	// text centering
	GetTableValue(temp4, arrayPos3, MenuControl_LetterWidthNumbers)
	temp7 += temp4
	temp7--

	temp7 += 3

	temp1 = arrayPos2
	temp1 /= 10
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp7 += temp4
	temp7--

	temp1 *= 10
	temp1 -= arrayPos2
	FlipSign(temp1)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp7 += temp4
	temp7--

	temp7 += 6

	temp1 = arrayPos1
	temp1 /= 10
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp7 += temp4
	temp7--

	temp1 *= 10
	temp1 -= arrayPos1
	FlipSign(temp1)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp7 += temp4
	temp7--

	temp7 /= 2
	temp0 -= temp7

	//actual drawing
	object.frame = arrayPos3
	object.frame += 210

	DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)
	GetTableValue(temp4, arrayPos3, MenuControl_LetterWidthNumbers)
	temp0 += temp4
	temp0--

	DrawSpriteScreenFX(220, FX_INK, temp0, object.drawPos.y)
	temp0 += 3

	temp1 = arrayPos2
	temp1 /= 10
	object.frame = temp1
	object.frame += 210

	DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp0 += temp4
	temp0--

	temp1 *= 10
	temp1 -= arrayPos2
	FlipSign(temp1)

	object.frame = temp1
	object.frame += 210

	DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp0 += temp4
	temp0--

	DrawSpriteScreenFX(221, FX_INK, temp0, object.drawPos.y)
	temp0 += 6

	temp1 = arrayPos1
	temp1 /= 10
	object.frame = temp1
	object.frame += 210

	DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp0 += temp4
	temp0--

	temp1 *= 10
	temp1 -= arrayPos1
	FlipSign(temp1)

	object.frame = temp1
	object.frame += 210

	DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)
	GetTableValue(temp4, temp1, MenuControl_LetterWidthNumbers)
	temp0 += temp4
	temp0--

	CopyPalette(0, 171, 0, 50, 1)	
end function		

function Menu_DrawTextString
	temp0 = object.drawPos.x
	temp7 = 0
	if object.textCenterIt == 1
		arrayPos0 = 0
		GetTextInfo(temp1, 2, TEXTINFO_TEXTSIZE, object.index, 0)

		// Now cycle through the letters in the string
		while temp1 > 0
			GetTextInfo(object.letterID, 2, TEXTINFO_TEXTDATA, object.index, arrayPos0)
			object.frame = object.letterID

			if temp2 == temp6
				CopyPalette(0, 149, 0, 50, 1)
			end if

			switch object.fontSize
			case FONT_SMALL
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame -= 64
						temp3 = MenuControl_LetterWidth
						temp5 = object.frame
						temp5--
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame -= 69
						temp3 = MenuControl_LetterWidth
						temp5 = object.frame
						temp5--
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_RandomCharacters
					temp5 = 0
				end if
				if object.letterID == 46
					object.frame = 158
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if
				if object.letterID == 33
					object.frame = 159
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if

				if object.letterID == 64
					object.drawPos.y += 15
					object.frame = 0
					temp0 = object.drawPos.x
					temp3 = MenuControl_RandomCharacters
					temp5 = 1				
				end if
				break
			case FONT_LARGE	
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame -= 11
						temp3 = MenuControl_LetterWidthLarge
						temp5 = object.letterID
						temp5 -= 65
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame -= 17
						temp3 = MenuControl_LetterWidthLarge
						temp5 = object.letterID
						temp5 -= 97
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_RandomCharacters
					temp5 = 0
				end if
				break

			case FONT_TINY
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame += 41
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.letterID
						temp5 -= 65
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame += 35
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.letterID
						temp5 -= 97
						temp5 += 26
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1
				end if

				if object.letterID == 64
					object.drawPos.y += 6
					object.frame = 0
					temp0 = object.drawPos.x
					temp3 = MenuControl_RandomCharacters
					temp5 = 1				
				end if

				if object.letterID == 46
					object.frame = 205
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if
				break
			end switch



			// Move on to the next letter that we've stored
			arrayPos0++

			// Then decrease the amount of letters we have left
			temp1--

			// Finally, space out each character
				GetTableValue(temp4, temp5, temp3)
				temp7 += temp4
				if object.fontSize == FONT_TINY
					temp7++
				else
					temp7--
				end if
		loop
	end if
	temp7 /= 2
	temp7++
	temp0 -= temp7

	arrayPos0 = 0

	GetTextInfo(temp1, 2, TEXTINFO_TEXTSIZE, object.index, 0)

	// Now cycle through the letters in the string
	while temp1 > 0
		GetTextInfo(object.letterID, 2, TEXTINFO_TEXTDATA, object.index, arrayPos0)
		object.frame = object.letterID

		if temp2 == temp6
			CopyPalette(0, 149, 0, 50, 1)
		end if

		switch object.fontSize
		case FONT_SMALL
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame -= 64
					temp3 = MenuControl_LetterWidth
					temp5 = object.frame
					temp5--
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame -= 69
					temp3 = MenuControl_LetterWidth
					temp5 = object.frame
					temp5--
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_RandomCharacters
				temp5 = 0
			end if
			if object.letterID == 46
				object.frame = 158
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 33
				object.frame = 159
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 44
				object.frame = 224
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 39
				object.frame = 226
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 63
				object.frame = 225
				temp3 = MenuControl_LetterWidth
				temp5 = 4
			end if

			if object.letterID == 64
				object.drawPos.y += 15
				object.frame = 0
				temp0 = object.drawPos.x
				temp3 = MenuControl_RandomCharacters
				temp5 = 1				
			end if
			break
		case FONT_LARGE	
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame -= 11
					temp3 = MenuControl_LetterWidthLarge
					temp5 = object.letterID
					temp5 -= 65
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame -= 17
					temp3 = MenuControl_LetterWidthLarge
					temp5 = object.letterID
					temp5 -= 97
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_RandomCharacters
				temp5 = 0
			end if
			break

		case FONT_TINY
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame += 41
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 65
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame += 35
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 97
					temp5 += 26
				end if
			end if

			if object.letterID >= 48
				if object.letterID <= 57
					object.frame += 123
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 48
					temp5 += 26
					temp5 += 26
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_TinyLetterWidth
				temp5 = 1
			end if

			if object.letterID == 64
				object.drawPos.y += 8
				object.frame = 0
				temp0 = object.drawPos.x
				temp0--
				temp3 = MenuControl_RandomCharacters
				temp5 = 1				
			end if
			if object.letterID == 46
				object.frame = 205
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.letterID == 44
				object.frame = 206
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.letterID == 33
				object.frame = 208
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.letterID == 39
				object.frame = 207
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			CopyPalette(0, 154, 0, 1, 1)
			break
		end switch

		// Now we'll start drawing
		DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)

		// Move on to the next letter that we've stored
		arrayPos0++

		// Then decrease the amount of letters we have left
		temp1--

		// Finally, space out each character
		GetTableValue(temp4, temp5, temp3)
		temp0 += temp4
		if object.fontSize == FONT_TINY
			temp0++
		else
			temp0--
		end if	

		CopyPalette(0, 171, 0, 50, 1)	
		SetPaletteEntry(0, 1, 0)
	loop

	// set it back so nothing bad happens
	object.textCenterIt = 0
end function

event ObjectMain

	if object.touchDelay > 0
		object.touchDelay--
	end if	

	if object.controlMode == 1
		inputPress.left = 0
		inputPress.right = 0
		inputPress.up = 0
		inputPress.down = 0
		inputPress.buttonA = 0
		inputPress.buttonB = 0
	end if

	if object.touchDelay == 0
		temp0 = 3
		temp1 = screen.ycenter
		temp1 += 8
		temp2 = 0
		while temp2 < 6
			temp3 = temp0
			temp3 += 80
			temp4 = temp1
			temp4 += 11
			CheckTouchRect(temp0, temp1, temp3, temp4)
			if checkResult > -1
				saved.mobile = true
				if object.currentSelection == temp2

					if object.summonWindow == 0
						if object.state != 5
							if object.state != 4
								object.secondSelection = 0
								object.bgBoxSize.x = 0
								object.bgBoxSize.y = 0
								object.alpha = 0
								object.windowAlpha = 0
								object.touchDelay = 10

								if object.state == 10
									if object.currentSelection != 2
										ResetObjectEntity(OPTIONS_SLOT, 0, 0, 0, 0)
										arrayPos0 = 81
										arrayPos1 = 41
										temp0 = 0
										while temp0 < 20
											ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 1, 0, 0)
											ResetObjectEntity(object[arrayPos1].entityPos, TypeName[Blank Object], 1, 0, 0)
											arrayPos0++
											arrayPos1++
											temp0++
										loop			
										WriteSaveRAM()
									end if
								end if

								switch object.currentSelection
								case 0
									object.state = 5
									stage.listPos = StageName[P - SAVE SELECT]
									PlaySfx(SfxName[Select], false)
									break
								case 1
									object.state = 2
									object.summonWindow = 1
									PlaySfx(SfxName[Select], false)
									break
								case 2	
									if object.state != 10
										object.controlMode = 0
										ResetObjectEntity(OPTIONS_SLOT, TypeName[Options], 0, 0, 0)
										object[OPTIONS_SLOT].drawOrder = 5
										object[OPTIONS_SLOT].priority = PRIORITY_ACTIVE
										object.state = 10
										PlaySfx(SfxName[Select], false)
									end if	
									break
								case 3
									object.summonWindow = 1
									object.secondSelection = 0
									object.state = 6
									PlaySfx(SfxName[Select], false)
									break
								case 4
									object.state = 4
									PlaySfx(SfxName[Select], false)
									break
								case 5
									CallNativeFunction(ExitGame)
									PlaySfx(SfxName[Select], false)
									break
								end switch
							end if		
						end if		
					end if		
				else
					if object.summonWindow == 0
						if object.state != 5
							if object.state != 4				
								PlaySfx(SfxName[Hover], false)	
								object.currentSelection = temp2
								object.touchDelay = 10
							end if	
						end if	
					end if	
				end if
			end if
			
			temp1 += 16
			temp2++
		loop
	end if		

	switch object.state
	case 0
		if MenuIntroSkip == 1
			if object.timer > 0
				object.timer -= 8
			else
				object.timer = 0
				MenuIntroSkip = 0
				fadeColor = 0
			end if

			temp0 = fadeColor
			temp0 >>= 16
			temp1 = fadeColor
			temp1 &= 0xFF00
			temp1 >>= 8
			temp2 = fadeColor
			temp2 &= 255
			SetClassicFade(temp0, temp1, temp2, object.timer)			
		else	
			if inputPress.up == 1
				object.currentSelection--
				PlaySfx(SfxName[Hover], false)
				while object.currentSelection < 0
					object.currentSelection += 6
				loop
			else
				if inputPress.down == 1
					object.currentSelection++
					PlaySfx(SfxName[Hover], false)
					object.currentSelection %= 6
				else
					temp0 = inputPress.buttonA
					temp0 |= inputPress.start
					if temp0 == 1
						PlaySfx(SfxName[Select], false)
						object.secondSelection = 0
						object.bgBoxSize.x = 0
						object.bgBoxSize.y = 0
						object.alpha = 0
						object.windowAlpha = 0

						switch object.currentSelection
						case 0
							object.state = 5
							stage.listPos = StageName[P - SAVE SELECT]
							break
						case 1
							object.state = 2
							object.summonWindow = 1
							break
						case 2	
							object.controlMode = 0
							ResetObjectEntity(OPTIONS_SLOT, TypeName[Options], 0, 0, 0)
							object[OPTIONS_SLOT].drawOrder = 5
							object[OPTIONS_SLOT].priority = PRIORITY_ACTIVE
							object.state = 10
							break
						case 3
							object.summonWindow = 1
							object.secondSelection = 0
							object.state = 6
							break
						case 4
							object.state = 4
							break
						case 5
							CallNativeFunction(ExitGame)
							break
						end switch
					end if
				end if
			end if
		end if	
		break
	case 1
		if inputPress.up == 1
			row.highlight--
			while row.highlight < 0
				row.highlight += 2
			loop
		else
			if inputPress.down == 1
				row.highlight++
				row.highlight %= 2
			end if
		end if

		if inputPress.left == 1
			column.highlight--
			while column.highlight < 0
				column.highlight += 6
			loop
		else
			if inputPress.right == 1
				column.highlight++
				column.highlight %= 6
			end if
		end if

		if inputPress.buttonB == 1
			object.state = 0

			temp0 = 0
			arrayPos0 = object[+20].entityPos

			while temp0 < 12
				ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 0, 0, 0)
				arrayPos0++
				temp0++
			loop
			object[-1].drawOrder = 5
		end if

		object.secondSelection = row.highlight
		object.secondSelection *= 6
		object.secondSelection += column.highlight
		break
	case 2
		if inputPress.up == 1
			object.secondSelection--

			PlaySfx(SfxName[Hover], false)
			while object.secondSelection < 0
				CallNativeFunction2(13, 0, "Data/Game/FreddyMenu.txt")
				if checkResult == false
					object.secondSelection += 3
				else
					object.secondSelection += 5
				end if	
			loop
		else
			if inputPress.down == 1
				object.secondSelection++
				PlaySfx(SfxName[Hover], false)
				CallNativeFunction2(13, 0, "Data/Game/FreddyMenu.txt")
				if checkResult == false
					object.secondSelection %= 3
				else
					object.secondSelection %= 5
				end if
			end if
		end if

		temp0 = 320
		temp2 = temp0
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2
		temp2 *= 2
		temp1 += temp2
		temp1 -= 10
		temp2 = temp1
		temp2 += 10
		CheckTouchRect(temp1, 1, temp2, 10)
		if checkResult > -1
			inputPress.buttonB = true
		end if	

		temp4 = 0
		CallNativeFunction2(13, 0, "Data/Game/FreddyMenu.txt")
		if checkResult == false
			temp7 = 3
		else
			temp7 = 5
		end if		
		temp1 = 20
		temp1 -= object.GameModesY
		while temp4 < temp7
			temp0 = 320
			temp5 = screen.xcenter
			temp2 = temp0
			temp2 /= 2
			temp5 -= temp2
			temp6 = temp5
			temp6 += temp0

			temp3 = temp1
			temp3 += 70

			CheckTouchRect(temp5, temp1, temp6, temp3)
			if checkResult > -1
				if object.touchDelay == 0
					if object.secondSelection == temp4
						PlaySfx(SfxName[Select], false)
						inputPress.buttonA = true
					else
						object.secondSelection = temp4
						PlaySfx(SfxName[Hover], false)
					end if	
					object.touchDelay = 10
				end if	
			end if
			temp1 += 95
			temp4++
		loop	

		CallNativeFunction2(13, 0, "Data/Game/FreddyMenu.txt")
		if checkResult == true

			if object.secondSelection <= 1
				temp2 = 0
			else
				temp2 = object.secondSelection
				temp2 *= 60
				temp2 += 18
			end if	
			//SLIDING STUFF
			temp0 = temp2
			temp0 -= object.GameModesY
			Abs(temp0)

			temp1 = temp2
			temp1 -= object.GameModesY

			//Make sure it's exactly in the spot
			if temp0 < 5
				if object.GameModesY > temp2
					object.GameModesY--
				else
					if object.GameModesY < temp2
						object.GameModesY++
					else
						object.GameModesY = temp2
					end if
				end if
			else
				temp1 >>= 2
				object.GameModesY += temp1
			end if				
		else
			if object.secondSelection == 0
				if object.GameModesY > 0
					object.GameModesY -= 15
				else
					object.GameModesY = 0
				end if	
			end if
			if object.secondSelection == 2
				if object.GameModesY < 60
					object.GameModesY += 15
				else
					object.GameModesY = 60
				end if	
			end if	
		end if	

		if inputPress.buttonB == 1
			object.summonWindow = 2
		end if
		if object.summonWindow == 0
			object.state = 0

			temp0 = 0
			arrayPos0 = object[+20].entityPos

			while temp0 < 3
				ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 0, 0, 0)
				arrayPos0++
				temp0++
			loop
		end if

		temp0 = inputPress.buttonA
		temp0 |= inputPress.start
		if temp0 == 1
			if object.summonWindow == 1
				PlaySfx(SfxName[Select], false)
				object.timer = 0
				object.state++
			end if	
		end if
		break
	case 3
		music.volume -= 4
		object.timer += 8
		MenufadeColor = 1
		if object.timer >= 256
			StopMusic()
			loading = 1
			switch object.secondSelection
				case 0 //Time Attack
					stage.activeList = PRESENTATION_STAGE
					stage.listPos = StageName[P - TIME ATTACK]
					LoadStage()
					break
				case 1 //Arcade
					stage.activeList = PRESENTATION_STAGE
					stage.listPos = StageName[P - ARCADE]
					LoadStage()
					break
				case 2 //Golf
					stage.activeList = PRESENTATION_STAGE
					stage.listPos = StageName[P - GOLF MENU]
					LoadStage()
					break
				case 3 //secrets
					stage.activeList = BONUS_STAGE
					stage.listPos = StageName[B - FREDDY MENU]
					LoadStage()
					break		
				case 4 //secrets
					stage.activeList = BONUS_STAGE
					stage.listPos = StageName[B - SLENDERMENU]
					LoadStage()
					break								
			end switch
		end if
		break
	case 4
		music.volume -= 4
		object.timer += 8
		SetClassicFade(0, 0, 0, object.timer)
		if object.timer >= 256
			StopMusic()
			switch saved.language
				case 0 //English
					LoadTextFile(1, "Data/Game/MenuTextEN.txt")
					break
				case 1 //Portuguese
					LoadTextFile(1, "Data/Game/MenuTextPR.txt")
					break
				case 2 //Spanish
					LoadTextFile(1, "Data/Game/MenuTextSP.txt")
					break
				case 3 //French
					LoadTextFile(1, "Data/Game/MenuTextFR.txt")
					break
				case 4 //German
					LoadTextFile(1, "Data/Game/MenuTextDE.txt")
					break
			end switch
			ResetObjectEntity(object.entityPos, TypeName[Mod Menu], 0, 0, 0)

			object.priority = PRIORITY_ACTIVE
			object.value15 = 320
			object[-1].priority = PRIORITY_INACTIVE
			object[-2].priority = PRIORITY_INACTIVE
		end if
		break
	case 5
		music.volume -= 4
		object.timer += 8
		MenufadeColor = 1
		if object.timer >= 260
			loading = 1
			StopMusic()
			LoadStage()
		end if
		break
	case 6	
		if inputPress.up == 1
			row.highlight--
			PlaySfx(SfxName[Hover], false)
			while row.highlight < 0
				row.highlight += 2
			loop			
		else
			if inputPress.down == 1
				row.highlight++
				PlaySfx(SfxName[Hover], false)
				row.highlight %= 2
			end if
		end if
		
		if inputPress.left == 1
			column.highlight--
			PlaySfx(SfxName[Hover], false)
			while column.highlight < 0
				column.highlight += 2
			loop
		else
			if inputPress.right == 1
				column.highlight++
				PlaySfx(SfxName[Hover], false)
				column.highlight %= 2
			end if
		end if

		temp0 = 320
		temp2 = temp0
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2
		temp2 *= 2
		temp1 += temp2
		temp1 -= 10
		temp2 = temp1
		temp2 += 10
		CheckTouchRect(temp1, 1, temp2, 10)
		if checkResult > -1
			inputPress.buttonB = true
		end if	

		object.secondSelection = row.highlight
		object.secondSelection *= 2
		object.secondSelection += column.highlight

		if inputPress.buttonB == 1
			object.summonWindow = 2
		end if
		if object.summonWindow == 0
			object.state = 0
		end if

		temp0 = 120
		temp5 = screen.xcenter
		temp2 = temp0
		temp2 /= 2
		temp5 -= temp2
		temp5 -= 65
		temp6 = temp5
		temp6 += temp0

		temp1 = 68
		temp3 = temp1
		temp3 += 70

		CheckTouchRect(temp5, temp1, temp6, temp3)
		if checkResult > -1
			if object.touchDelay == 0
				if object.secondSelection == 0
					PlaySfx(SfxName[Select], false)
					inputPress.buttonA = true
				else
					row.highlight = 0
					column.highlight = 0
					PlaySfx(SfxName[Hover], false)
				end if	
				object.touchDelay = 10
			end if	
		end if

		temp0 = 120
		temp5 = screen.xcenter
		temp2 = temp0
		temp2 /= 2
		temp5 -= temp2
		temp5 += 65
		temp6 = temp5
		temp6 += temp0

		temp1 = 68
		temp3 = temp1
		temp3 += 70

		CheckTouchRect(temp5, temp1, temp6, temp3)
		if checkResult > -1
			if object.touchDelay == 0
				if object.secondSelection == 1
					PlaySfx(SfxName[Select], false)
					inputPress.buttonA = true
				else
					row.highlight = 0
					column.highlight = 1
					PlaySfx(SfxName[Hover], false)
				end if	
				object.touchDelay = 10
			end if	
		end if

		temp0 = 120
		temp5 = screen.xcenter
		temp2 = temp0
		temp2 /= 2
		temp5 -= temp2
		temp5 -= 65
		temp6 = temp5
		temp6 += temp0

		temp1 = 148
		temp3 = temp1
		temp3 += 70

		CheckTouchRect(temp5, temp1, temp6, temp3)
		if checkResult > -1
			if object.touchDelay == 0
				if object.secondSelection == 2
					PlaySfx(SfxName[Select], false)
					inputPress.buttonA = true
				else
					row.highlight = 1
					column.highlight = 0
					PlaySfx(SfxName[Hover], false)
				end if	
				object.touchDelay = 10
			end if	
		end if

		temp0 = 120
		temp5 = screen.xcenter
		temp2 = temp0
		temp2 /= 2
		temp5 -= temp2
		temp5 += 65
		temp6 = temp5
		temp6 += temp0

		temp1 = 148
		temp3 = temp1
		temp3 += 70

		CheckTouchRect(temp5, temp1, temp6, temp3)
		if checkResult > -1
			if object.touchDelay == 0
				if object.secondSelection == 3
					PlaySfx(SfxName[Select], false)
					inputPress.buttonA = true
				else
					row.highlight = 1
					column.highlight = 1
					PlaySfx(SfxName[Hover], false)
				end if	
				object.touchDelay = 10
			end if	
		end if

		temp0 = inputPress.buttonA
		temp0 |= inputPress.start
		if temp0 == 1
			if object.summonWindow == 1
				GetTableValue(temp5, object.secondSelection, ExtrasUnlock)
				arrayPos0 = temp5
				checkGreater(saveRAM[arrayPos0], 0)
				temp6 = checkResult
				checkEqual(temp5, 0)
				temp6 |= checkResult
				if temp6 == 1			
					PlaySfx(SfxName[Select], false)
					object.timer = 0
					object.charFrameX = 17
					Rand(temp0, 100)
					if temp0 >= 50
						if temp0 <= 55
							selfAware = 1
						end if
					end if

					object.state++
				else
					PlaySfx(SfxName[Bonus Points], 0)
				end if
			end if	
		end if
		break
	case 7
		switch object.secondSelection
			case 1 //Emerald Gauntlet
				if object.timer == 0
					StopMusic()
					PlaySfx(SfxName[Warp], 0)
				end if
				object.timer += 8
				MenufadeColor = 2
				if object.timer >= 768			
					fadeColor = color7
					fadeColor <<= 16
					temp0 = color7
					temp0 <<= 8
					fadeColor += temp0
					fadeColor += color7
					LoadPalette("SpecialStage.act", 0, 0, 0, 128)
					options.gameMode = 4
					stage.playerListPos = 0
					stage.activeList = SPECIAL_STAGE
					stage.listPos = 0
					stage.debugMode = 0
					loading = 1
					LoadStage()
				end if
				break
			case 0 //Boss Rush
				if object.timer == 0

					temp0 = 120
					temp0 /= 3
					temp0 -= 2
					temp5 = screen.xcenter
					temp2 = temp0
					temp2 /= 2
					temp5 -= temp2
					temp5 -= 65
					temp5 += 42
					temp6 = temp5
					temp6 += temp0

					temp1 = 68
					temp3 = temp1
					temp3 += 70

					CheckTouchRect(temp5, temp1, temp6, temp3)
					if checkResult > -1
						if object.touchDelay == 0
							inputPress.right = true
							PlaySfx(SfxName[Hover], false)	
							object.touchDelay = 10
						end if	
					end if

					temp0 = 120
					temp0 /= 3
					temp0 -= 2
					temp5 = screen.xcenter
					temp2 = temp0
					temp2 /= 2
					temp5 -= temp2
					temp5 -= 65
					temp6 = temp5
					temp6 += temp0

					temp1 = 68
					temp3 = temp1
					temp3 += 70

					CheckTouchRect(temp5, temp1, temp6, temp3)
					if checkResult > -1
						if object.touchDelay == 0
							inputPress.start = true
							PlaySfx(SfxName[Hover], false)	
							object.touchDelay = 10
						end if	
					end if

					temp0 = 120
					temp0 /= 3
					temp0 -= 2
					temp5 = screen.xcenter
					temp2 = temp0
					temp2 /= 2
					temp5 -= temp2
					temp5 -= 65
					temp5 -= 42
					temp6 = temp5
					temp6 += temp0

					temp1 = 68
					temp3 = temp1
					temp3 += 70

					CheckTouchRect(temp5, temp1, temp6, temp3)
					if checkResult > -1
						if object.touchDelay == 0
							inputPress.left = true
							PlaySfx(SfxName[Hover], false)	
							object.touchDelay = 10
						end if	
					end if

					if inputPress.left == 1
						object.charHighlight--
						PlaySfx(SfxName[Hover], false)
						while object.charHighlight < 0
							object.charHighlight += 8
						loop
					else
						if inputPress.right == 1
							object.charHighlight++
							PlaySfx(SfxName[Hover], false)
							object.charHighlight %= 8
						end if
					end if			

					temp0 = 320
					temp2 = temp0
					temp2 /= 2
					temp1 = screen.xcenter
					temp1 -= temp2
					temp2 *= 2
					temp1 += temp2
					temp1 -= 10
					temp2 = temp1
					temp2 += 10
					CheckTouchRect(temp1, 1, temp2, 10)
					if checkResult > -1
						object.state--
						object.summonWindow = 2
					end if	

					if inputPress.buttonB == 1
						object.state--
						selfAware = 0
					end if

					temp0 = inputPress.buttonA
					temp0 |= inputPress.start
					if temp0 == 1
						object.timer++
					end if
				else
					object.timer += 8
					music.volume -= 10
					MenufadeColor = 1
					if object.timer >= 256
						StopMusic()
						options.gameMode = 2
						if object.charHighlight >= 3
							stage.playerListPos = object.charHighlight
							stage.playerListPos += 2
						else
							stage.playerListPos = object.charHighlight
						end if
						stage.activeList = BONUS_STAGE
						stage.listPos = StageName[B - BOSS RUSH]
						stage.debugMode = 0
						loading = 1
						LoadStage()
					end if
				end if	
				break
			case 2 //Special Maker
				if object.timer == 0
					StopMusic()
					PlaySfx(SfxName[Warp], 0)
				end if
				object.timer += 8
				MenufadeColor = 2
				if object.timer >= 768
					fadeColor = color7
					fadeColor <<= 16
					temp0 = color7
					temp0 <<= 8
					fadeColor += temp0
					fadeColor += color7
					LoadPalette("SpecialStage.act", 0, 0, 0, 128)
					options.gameMode = 0
					stage.playerListPos = 0
					stage.activeList = SPECIAL_STAGE
					stage.listPos = 7
					stage.debugMode = 1
					loading = 1
					LoadStage()
				end if
				break
			case 3	
				object.scrollAchieveY = 17
				achieveY = 17
				object.state++
				break
		end switch		
		break
	case 8	

		CheckTouchRect(0, 12, screen.xsize, 42)
		if checkResult > -1
			inputDown.up = 1
		end if

		temp0 = screen.ysize
		temp0 -= 12
		temp1 = temp0
		temp1 -= 40
		CheckTouchRect(0, temp1, screen.xsize, temp0)
		if checkResult > -1
			inputDown.down = 1
		end if

		if inputDown.up == 1
			if object.scrollAchieveY < 17
				object.scrollAchieveY += 5
			else
				object.scrollAchieveY = 17
			end if
		else
			if inputDown.down == 1
				temp0 = -527
				if object.scrollAchieveY > temp0
					object.scrollAchieveY -= 5
				else
					object.scrollAchieveY = temp0
				end if
			end if
		end if
		achieveY = object.scrollAchieveY
		temp0 = 320
		temp2 = temp0
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2
		temp2 *= 2
		temp1 += temp2
		temp1 -= 10
		temp2 = temp1
		temp2 += 10
		CheckTouchRect(temp1, 1, temp2, 10)
		if checkResult > -1
			object.summonWindow = 2
		end if				
		if object.summonWindow == 0
			object.state = 0
		end if				
		if inputPress.buttonB == 1
			object.state = 6
		end if		
		break
	case 10	
		object.controlMode = 0
		if deleteCheck == 0
			if optionCheck == 0
				if inputPress.buttonB == 1
					object.state = 0
					ResetObjectEntity(OPTIONS_SLOT, 0, 0, 0, 0)
					arrayPos0 = 81
					arrayPos1 = 41
					temp0 = 0
					while temp0 < 20
						ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 1, 0, 0)
						ResetObjectEntity(object[arrayPos1].entityPos, TypeName[Blank Object], 1, 0, 0)
						arrayPos0++
						arrayPos1++
						temp0++
					loop			
					WriteSaveRAM()
				end if	
			end if					
		end if					
		break
	end switch
	//CallFunction(SetTextFileLanguage)
end event


event ObjectDraw
	object.drawOrder = 5
	object.drawPos.x = 3
	object.drawPos.x += object[33].value7
	object.drawPos.y = screen.ycenter
	object.drawPos.y += 8
	temp2 = 0
	object.inkEffect = 0
	while temp2 < 6
		object.index = temp2
		object.index++
		temp6 = object.currentSelection
		object.fontSize = FONT_SMALL
		object.textCenterIt = 0
		CallFunction(Menu_DrawTextString)
		object.drawPos.y += 16
		temp2++
	loop

	if object.summonWindow > 0

		object.inkEffect = INK_ALPHA

		if object.summonWindow == 1
			if object.bgBoxSize.x >= 320
				object.bgBoxSize.x = 320
				object.bgBoxSize.y = screen.ysize
				if object.alpha < 0x100
					object.alpha += 0x13
				else
					object.alpha = 0x100
					object.controlMode = 0
				end if

				if object.alpha == 0x26
					PlaySfx(SfxName[Window Open], false)
				end if
			else
				object.controlMode = 1
				temp0 = 335
				temp0 -= object.bgBoxSize.x
				temp0 >>= 3
				object.bgBoxSize.x += temp0

				temp0 = 250
				temp0 -= object.bgBoxSize.y
				temp0 >>= 3
				object.bgBoxSize.y += temp0		
			end if
			if object.windowAlpha < 0x100
				object.windowAlpha += 0x13
			else
				object.windowAlpha = 0x100
			end if			
		else		
			temp0 = 0x100
			temp0 -= 0x39
			if object.alpha == temp0
				PlaySfx(SfxName[Window Close], false)
			end if		
			if object.alpha > 0
				object.controlMode = 1
				object.alpha -= 0x13
			else
				object.alpha = 0
				if object.windowAlpha > 0
					object.windowAlpha -= 0x13
				else
					object.windowAlpha = 0
				end if						
				if object.bgBoxSize.x < 4
					object.bgBoxSize.x = 0
					object.bgBoxSize.y = 0
					object.controlMode = 0
					object.summonWindow = 0
				else
					temp0 = 0
					temp0 -= object.bgBoxSize.x
					temp0 >>= 3
					object.bgBoxSize.x += temp0

					temp0 = 0
					temp0 -= object.bgBoxSize.y
					temp0 >>= 3
					object.bgBoxSize.y += temp0
				end if	
			end if		
		end if	

		temp0 = object.bgBoxSize.x
		temp0 /= 2
		DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, temp0)

		temp0 = 320
		temp2 = object.bgBoxSize.x
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2
		temp3 = object.bgBoxSize.y
		temp3 >>= 1
		FlipSign(temp3)
		temp3 += screen.ycenter		
		temp3 -= BOX_OFFSET
		if object.alpha >= 1
			DrawRect(temp1, temp3, object.bgBoxSize.x, object.bgBoxSize.y, color7, color7, color7, object.windowAlpha)
			DrawRect(temp1, temp3, object.bgBoxSize.x, object.bgBoxSize.y, color7, color7, color6, 100)		
		end if	

		switch object.state
		case 2
		case 3
			object.drawPos.x = screen.xcenter
			object.drawPos.x -= 23
			object.drawPos.y = 22
			object.drawPos.y -= object.GameModesY
			temp2 = 0
			while temp2 < 3
				temp0 = 160
				temp0 += temp2
				temp1 = screen.xcenter
				temp1 -= 90
				temp3 = object.drawPos.y
				temp3 += 30

				SetActivePalette(1, 0, 256)
				DrawSpriteScreenFX(temp0, FX_INK, temp1, temp3)
				SetActivePalette(0, 0, 256)

				object.index = temp2
				object.index += 7
				object.fontSize = FONT_LARGE
				temp6 = object.secondSelection
				CallFunction(Menu_DrawTextString)
				object.drawPos.y += 22

				object.index = temp2
				object.index += 10
				object.fontSize = FONT_SMALL
				temp6 = object.secondSelection
				CallFunction(Menu_DrawTextString)
				object.drawPos.y += 25

				temp0 = 300
				temp5 = temp0
				temp5 /= 2
				temp1 = screen.xcenter
				temp1 -= temp5

				DrawRect(temp1, object.drawPos.y, temp0, 1, color4, color1, color4, object.alpha)		

				object.drawPos.y += 15

				temp2++
			loop

			CallNativeFunction2(13, 0, "Data/Game/FreddyMenu.txt")
			if checkResult == true
				temp2 = 0
				while temp2 < 2
					temp0 = 222
					temp0 += temp2
					temp1 = screen.xcenter
					temp1 -= 90
					temp3 = object.drawPos.y
					temp3 += 30

					SetActivePalette(1, 0, 256)
					DrawSpriteScreenFX(temp0, FX_INK, temp1, temp3)
					SetActivePalette(0, 0, 256)

					object.index = temp2
					object.index += 222
					object.fontSize = FONT_LARGE
					temp6 = object.secondSelection
					temp6 -= 3					
					CallFunction(Menu_DrawTextString)
					object.drawPos.y += 22

					object.index = temp2
					object.index += 224
					object.fontSize = FONT_SMALL
					temp6 = object.secondSelection
					temp6 -= 3
					CallFunction(Menu_DrawTextString)
					object.drawPos.y += 25

					temp0 = 300
					temp5 = temp0
					temp5 /= 2
					temp1 = screen.xcenter
					temp1 -= temp5

					DrawRect(temp1, object.drawPos.y, temp0, 1, color4, color1, color4, object.alpha)		

					object.drawPos.y += 15

					temp2++
				loop
			end if	

			temp0 = 320
			temp2 = object.bgBoxSize.x
			temp2 /= 2
			temp1 = screen.xcenter
			temp1 -= temp2
			temp3 = object.bgBoxSize.y
			temp3 /= 25
			temp3++
			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			FlipSign(temp4)
			temp4 += screen.ycenter
			//temp4 -= BOX_OFFSET		
			if object.windowAlpha >= 0x100
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color7, color7, object.windowAlpha)
			end if	

			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			temp4 += screen.ycenter
			temp4 -= BOX_OFFSET		
			if object.alpha >= 1	
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color4, color6, object.windowAlpha)
			end if	

			temp1 += 6
			object.drawPos.x = temp1
			object.drawPos.y = 3
			object.index = 2
			object.fontSize = FONT_TINY
			temp6 = object.secondSelection
			CallFunction(Menu_DrawTextString)
			break
		case 8
			object.drawPos.x = screen.xcenter
			object.drawPos.x -= 23
			object.drawPos.y = 22
			object.drawPos.y -= object.GameModesY

			temp2 = 0
			while temp2 < 19
				temp7 = object.bgBoxSize.x
				temp7 /= 2
				temp1 = screen.xcenter
				temp1 -= temp7	
				temp1 += 6
				GetTableValue(arrayPos0, temp2, AchieveEarned)
				if saveRAM[arrayPos0] == 0				
					SetActivePalette(2, 0, 256)
				else
					SetActivePalette(1, 0, 256)
				end if	
				temp3 = temp2
				temp3 += 181
				if temp2 == 0
					switch saved.GHZwater
					case 0
						DrawSpriteScreenFX(temp3, FX_INK, temp1, achieveY)
						break
					case 1
						DrawSpriteScreenFX(202, FX_INK, temp1, achieveY)
						break
					case 2
						DrawSpriteScreenFX(201, FX_INK, temp1, achieveY)
						break
					end switch	
				else
					DrawSpriteScreenFX(temp3, FX_INK, temp1, achieveY)
				end if	
				SetActivePalette(0, 0, 256)

				temp1 += 58
				object.drawPos.x = temp1
				object.drawPos.y = achieveY
				object.drawPos.y++
				object.index = temp2
				object.index *= 2
				object.index += 26
				object.fontSize = FONT_SMALL
				temp6 = -1
				CallFunction(Menu_DrawTextString)	

				temp7 = object.bgBoxSize.x
				temp7 /= 2
				temp1 = screen.xcenter
				temp1 -= temp7	
				temp1 += 70
				temp1 -= 6
				
				achieveY += 17

				object.drawPos.x = temp1
				object.drawPos.y = achieveY
				object.index = temp2
				object.index *= 2
				object.index += 27		
				object.fontSize = FONT_TINY
				temp6 = -1
				CallFunction(Menu_DrawTextString)

				achieveY += 23
				temp2++	
			loop	

			temp0 = 320
			temp2 = object.bgBoxSize.x
			temp2 /= 2
			temp1 = screen.xcenter
			temp1 -= temp2
			temp3 = object.bgBoxSize.y
			temp3 /= 25
			temp3++
			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			FlipSign(temp4)
			temp4 += screen.ycenter
			//temp4 -= BOX_OFFSET		
			if object.windowAlpha >= 0x100
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color7, color7, object.windowAlpha)
			end if	

			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			temp4 += screen.ycenter
			temp4 -= BOX_OFFSET		
			temp2 = object.bgBoxSize.x
			temp2 /= 2
			temp1 = screen.xcenter
			temp1 -= temp2			
			if object.alpha >= 1	
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color4, color6, object.windowAlpha)
			end if		

			temp2 = object.bgBoxSize.x
			temp2 /= 2
			temp1 = screen.xcenter
			temp1 -= temp2
			temp1 += 6
			object.drawPos.x = temp1
			object.drawPos.y = 3
			object.index = 16
			object.fontSize = FONT_TINY
			temp6 = object.secondSelection
			CallFunction(Menu_DrawTextString)

			// Scroll Bar
			temp0 = 527
			temp0 -= 17

			// Prevent divide-by-zero hell
			if temp0 > 0
				temp2 = temp1
				temp2 -= object.scrollAchieveY // normalized 0 to 544
				temp3 = temp2 
				temp3 *= 100 
				temp3 /= temp0

				if temp3 < 0
					temp3 = 0
				end if
				if temp3 > 100
					temp3 = 100
				end if

				temp6 = 32

				// barY based on percent of area
				temp5 = 211
				temp5 -= temp6
				temp4 = temp5
				temp4 *= temp3
				temp4 /= 100
				temp4 += 17
			end if

			// Draw scroll bar (darker block)
			temp7 = object.bgBoxSize.x
			temp7 /= 2
			temp1 = screen.xcenter
			temp1 += temp7	
			temp1 -= 4
			DrawRect(temp1, temp4, 1, temp6, color4, color1, color4, object.alpha)	

			if saved.mobile == 1		
				DrawSpriteScreenXY(227, screen.xcenter, 20)
				temp0 = screen.ysize
				temp0 -= 20
				DrawSpriteScreenXY(228, screen.xcenter, temp0)
			end if
			break
		case 6
		case 7
			object.drawPos.x = screen.xcenter
			object.drawPos.x -= 23
			object.drawPos.y = 22
			object.drawPos.y -= object.GameModesY

			temp0 = 320
			temp2 = object.bgBoxSize.x
			temp2 /= 2
			temp1 = screen.xcenter
			temp1 -= temp2
			temp3 = object.bgBoxSize.y
			temp3 /= 25
			temp3++
			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			FlipSign(temp4)
			temp4 += screen.ycenter
			//temp4 -= BOX_OFFSET		
			if object.windowAlpha >= 0x100
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color7, color7, object.windowAlpha)
			end if	

			temp0 = 120
			temp5 = screen.xcenter
			temp2 = temp0
			temp2 /= 2
			temp5 -= temp2
			temp5 -= 65
			SetActivePalette(1, 0, 256)
			DrawSpriteScreenFX(163, FX_INK, temp5, temp3)
			SetActivePalette(0, 0, 256)
			temp7 = object.alpha
			temp7 /= 2
			if temp7 > 10
				temp7 += 20
			end if	
			DrawRect(temp5, 68, temp0, 70, color4, 0, 0, temp7)	
			if object.secondSelection == 0
				DrawSpriteScreenFX(167, FX_INK, temp5, temp3)
			end if		

			temp5 = screen.xcenter
			temp2 = temp0
			temp2 /= 2
			temp5 -= temp2
			temp5 += 65
			SetActivePalette(1, 0, 256)
			DrawSpriteScreenFX(164, FX_INK, temp5, temp3)
			SetActivePalette(0, 0, 256)
			temp7 = object.alpha
			temp7 /= 2
			if temp7 > 10
				temp7 += 20
			end if	
			DrawRect(temp5, 68, temp0, 70, 0, color4, color4, temp7)		
			if object.secondSelection == 1
				DrawSpriteScreenFX(167, FX_INK, temp5, temp3)
			end if		

			temp5 = screen.xcenter
			temp2 = temp0
			temp2 /= 2
			temp5 -= temp2
			temp5 -= 65
			SetActivePalette(1, 0, 256)
			DrawSpriteScreenFX(165, FX_INK, temp5, 90)
			SetActivePalette(0, 0, 256)
			temp7 = object.alpha
			temp7 /= 2
			if temp7 > 10
				temp7 += 20
			end if	
			DrawRect(temp5, 148, temp0, 70, 0, color4, color4, temp7)	
			if object.secondSelection == 2
				DrawSpriteScreenFX(167, FX_INK, temp5, 90)
			end if					

			temp5 = screen.xcenter
			temp2 = temp0
			temp2 /= 2
			temp5 -= temp2
			temp5 += 65
			SetActivePalette(1, 0, 256)
			DrawSpriteScreenFX(166, FX_INK, temp5, 90)
			SetActivePalette(0, 0, 256)
			temp7 = object.alpha
			temp7 /= 2
			if temp7 > 10
				temp7 += 20
			end if	
			DrawRect(temp5, 148, temp0, 70, color4, color4, 0, temp7)	
			if object.secondSelection == 3
				DrawSpriteScreenFX(167, FX_INK, temp5, 90)
			end if					

			temp4 = object.bgBoxSize.y
			temp4 >>= 1
			temp4 += screen.ycenter
			temp4 -= BOX_OFFSET		
			if object.alpha >= 1	
				DrawRect(temp1, temp4, object.bgBoxSize.x, temp3, color7, color4, color6, object.windowAlpha)
			end if	

			temp1 += 6
			object.drawPos.x = temp1
			object.drawPos.y = 3
			CheckGreater(object.state, 6)
			temp0 = checkResult
			CheckEqual(object.secondSelection, 0)
			temp0 &= checkResult
			CheckEqual(selfAware, 1)
			temp0 &= checkResult
			if temp0 == 1		
				if object.timer == 0	
					object.index = 64
					object.index += object.charHighlight
				else
					if object.charHighlight == 7
						object.index = 72
					else
						object.index = 4
					end if
				end if	
			else
				object.index = 4
			end if	
			object.fontSize = FONT_TINY
			temp6 = object.secondSelection
			CallFunction(Menu_DrawTextString)

			object.index = 4
			object.fontSize = FONT_LARGE
			object.drawPos.x = screen.xcenter
			//object.drawPos.x += 5
			object.drawPos.y = 30
			temp6 = object.secondSelection
			object.textCenterIt = 1
			CallFunction(Menu_DrawTextString)

			if bossRushUnlock == 1
				object.index = 14
				temp5 = screen.xcenter
				temp2 = 120
				temp2 /= 2
				temp5 -= temp2	
			else	
				object.index = 17
				temp5 = screen.xcenter
				temp2 = 120
				temp2 /= 2
				temp5 -= temp2	
				//temp5 += 9			
			end if			
			object.fontSize = FONT_SMALL

			object.drawPos.x = temp5
			object.drawPos.y = 98
			CheckEqual(object.state, 7)
			temp0 = checkResult
			CheckEqual(object.secondSelection, 0)
			temp0 &= checkResult
			if temp0 == 1

				object.index = object.charHighlight
				object.index += 18

				object.drawPos.x -= 5
				object.drawPos.y -= 1
				temp6 = 16
				temp6 *= object.charHighlight
				temp6 += 17

				CheckEqual(object.charHighlight, 0)
				temp7 = checkResult
				CheckGreater(object.charFrameX, 128)
				temp7 &= checkResult
				if temp7 == 1
					if object.charFrameX < 145
						object.charFrameX += 1
					else
						object.charFrameX = temp6
					end if					
				else
					CheckEqual(object.charHighlight, 7)
					temp0 = checkResult
					CheckLower(object.charFrameX, 30)
					temp0 &= checkResult
					if temp0 == 1
						if object.charFrameX > 1
							object.charFrameX -= 1
						else
							object.charFrameX = temp6
						end if					
					else				
						if temp6 > object.charFrameX
							object.charFrameX += 1
						else
							if temp6 < object.charFrameX
								object.charFrameX -= 1
							else
								object.charFrameX = temp6
							end if
						end if
					end if
				end if	

				EditFrame(168, -8, -8, 16, 16, object.charFrameX, 486)
							
				DrawSpriteScreenFX(168, FX_INK, object.drawPos.x, object.drawPos.y)
				if saved.mobile == 0
					DrawSpriteScreenFX(169, FX_INK, object.drawPos.x, object.drawPos.y)
					DrawSpriteScreenFX(170, FX_INK, object.drawPos.x, object.drawPos.y)
				else	
					DrawSpriteScreenFX(229, FX_INK, object.drawPos.x, object.drawPos.y)
					DrawSpriteScreenFX(230, FX_INK, object.drawPos.x, object.drawPos.y)
				end if	
				object.drawPos.y += 10
				temp2 = -1
				temp6 = object.secondSelection	
			else
				object.drawPos.y += 8
				object.drawPos.x -= 5
				temp1 = 0
				temp2 = 0
				temp6 = object.secondSelection	
				CallFunction(DrawTimeExtra)						
				object.drawPos.y -= 16						
			end if
				
			temp5 -= 9
			object.drawPos.x = temp5
			object.drawPos.x += 4
			object.textCenterIt = 1		
			CallFunction(Menu_DrawTextString)				

			if emeraldGauntletUnlock == 1
				object.index = 13
				temp5 = screen.xcenter
				temp2 = 120
				temp2 /= 2
				temp5 += temp2
				temp5 += 5	
			else	
				object.index = 17
				temp5 = screen.xcenter
				temp2 = 120
				temp2 /= 2
				temp5 += temp2	
				temp5 += 5		
			end if
			object.fontSize = FONT_SMALL

			object.drawPos.x = temp5
			object.drawPos.y = 98
			object.drawPos.y += 8
			temp1 = 1
			temp2 = 1				
			temp6 = object.secondSelection			
			CallFunction(DrawTimeExtra)		
			object.drawPos.y -= 16						
			object.textCenterIt = 1
			CallFunction(Menu_DrawTextString)

			object.index = 15
			object.fontSize = FONT_SMALL
			temp5 = screen.xcenter
			temp2 = 120
			temp2 /= 2
			temp5 -= temp2	
			temp5 -= 4
			object.drawPos.x = temp5
			object.drawPos.y = 98
			object.drawPos.y += 80
			temp6 = object.secondSelection
			object.textCenterIt = 1
			temp2 = 2
			CallFunction(Menu_DrawTextString)

			object.index = 16
			object.fontSize = FONT_SMALL
			temp5 = screen.xcenter
			temp2 = 120
			temp2 /= 2
			temp5 += temp2
			temp5 += 5
			object.drawPos.x = temp5
			object.drawPos.y = 98
			object.drawPos.y += 80
			temp6 = object.secondSelection
			object.textCenterIt = 1
			temp2 = 3
			CallFunction(Menu_DrawTextString)


			break
		end switch

		temp0 = 320
		temp2 = temp0
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2

		temp2 *= 2
		temp1 += temp2
		DrawSpriteScreenFX(27, FX_INK, temp1, 3)			

		temp0 = 320
		temp2 = object.bgBoxSize.x
		temp2 /= 2
		temp1 = screen.xcenter
		temp1 -= temp2
		temp3 = object.bgBoxSize.y
		temp3 >>= 1
		FlipSign(temp3)
		temp3 += screen.ycenter		
		if object.summonWindow == 1
			if object.windowAlpha == 0x100
				temp7 = 255
				temp7 -= object.alpha
			else
				temp7 = object.windowAlpha
			end if	
		else
			if object.alpha > 0
				temp7 = 255
				temp7 -= object.alpha
			else
				temp7 = object.windowAlpha
			end if	
		end if	

		// orignally used classic tint
		if object.bgBoxSize.x == 320
			DrawRect(temp1, temp3, object.bgBoxSize.x, object.bgBoxSize.y, color7, color7, color7, temp7)
		else
			DrawRect(temp1, temp3, object.bgBoxSize.x, object.bgBoxSize.y, color7, color7, color7, temp7)
		end if		
	end if

	switch MenufadeColor
	case 1
		ClassicTint(0, 0, screen.xsize, screen.ysize, 0, 0, 0, object.timer)
		break
	case 2
		ClassicTint(0, 0, screen.xsize, screen.ysize, color7, color7, color7, object.timer)		
		break
	end switch
		
	if loading == 1
		object.drawPos.x = screen.xcenter
		object.drawPos.y = screen.ycenter
		object.drawPos.y += 5
		object.index = 185	
		object.fontSize = FONT_TINY
		object.textCenterIt = 1
		temp6 = -1

		if MenufadeColor == 1
			temp7 = color7
			temp7 <<= 16
			temp1 = color7
			temp1 <<= 8
			temp7 += temp1
			temp7 += color7		
			SetPaletteEntry(0, 154, temp7)	
		else
			SetPaletteEntry(0, 154, 0)			
		end if

		CallFunction(Menu_DrawTextString)

		object.drawPos.y = screen.ycenter
		object.drawPos.y -= 5
		SetActivePalette(1, 0, 256)
		DrawSpriteScreenFX(209, FX_INK, screen.xcenter, object.drawPos.y)
		SetActivePalette(0, 0, 256)
		foreach(TypeName[Sparkles], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].type = TypeName[Blank Object]
		next
	end if
	
end event


event ObjectStartup
	saved.mobile = false
	LoadSpriteSheet("DDLCMenu/Menu.gif")
	LoadPalette("MainMenu.act", 1, 0, 0, 256)
	LoadPalette("SpecialStage.act", 0, 0, 0, 96)
	LoadPalette("ElectricFlash.act", 3, 0, 0, 256)		

	CallFunction(SetTextFileLanguage)

	SpriteFrame(0, 0, 0, 0, 0, 0) // 0 Blank
	
	//Uppercase
	temp0 = 0
	temp2 = 78
	temp3 = 242
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 15, 12, temp2, temp3) 1-26
			temp1++
			temp2 += 16
		loop
		temp2 = 78
		temp0++
		temp3 += 13
	loop

	SpriteFrame(-8, 0, 4, 4, 236, 116) 27

	//Lowercase
	temp0 = 0
	temp2 = 78
	temp3 = 268
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 11, 14, temp2, temp3) 27-53
			temp1++
			temp2 += 12
		loop
		temp2 = 78
		temp0++
		temp3 += 15
	loop

	//Uppercase Large Font | 54-79
	temp0 = 0
	temp2 = 78
	temp3 = 298
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			if temp1 == 3
				if temp0 == 1
					SpriteFrame(0, 0, 27, 22, temp2, temp3) // Q
				else
					SpriteFrame(0, 0, 27, 20, temp2, temp3) 
				end if	
			else	
				SpriteFrame(0, 0, 27, 20, temp2, temp3) 
			end if
			temp1++
			temp2 += 28
		loop
		temp2 = 78
		temp0++
		temp3 += 21
	loop

	//Lowercase Large Font | 80-105
	temp0 = 0
	temp2 = 78
	temp3 = 298
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			if temp1 == 3
				if temp0 == 1
					SpriteFrame(0, 0, 27, 22, temp2, temp3) // Q
				else
					SpriteFrame(0, 0, 27, 20, temp2, temp3) 
				end if	
			else	
				SpriteFrame(0, 0, 27, 20, temp2, temp3) 
			end if
			temp1++
			temp2 += 28
		loop
		temp2 = 78
		temp0++
		temp3 += 21
	loop

	//Uppercase Tiny Font | 106-131
	temp0 = 0
	temp2 = 1
	temp3 = 242
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 5, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 6
	loop

	//Lowercase Tiny Font | 132-157
	temp0 = 0
	temp2 = 1
	temp3 = 254
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 7, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 7
	loop

	SpriteFrame(0, 0, 15, 12, 286, 255) 158 // 158 . small font
	SpriteFrame(0, 0, 15, 12, 302, 255) 158 // 159 ! small font

	// extras get your extras!!
	SpriteFrame(-62, -24, 123, 48, 322, 109) // 160
	SpriteFrame(-62, -24, 123, 48, 322, 158) // 161
	SpriteFrame(-62, -24, 123, 48, 322, 207) // 162
	SpriteFrame(0, 58, 120, 70, 307, 342) // 163
	SpriteFrame(0, 58, 120, 70, 428, 342) // 164
	SpriteFrame(0, 58, 120, 70, 307, 413) // 165
	SpriteFrame(0, 58, 120, 70, 428, 413) // 166	
	SpriteFrame(0, 58, 120, 70, 442, 269) // 167

	// char select bos rush
	SpriteFrame(-8, -8, 16, 16, 17, 486) // 168
	SpriteFrame(-16, -3, 6, 7, 1, 503) // 169
	SpriteFrame(10, -3, 6, 7, 8, 503) // 170
	
	// tiny numbers 171-180
	temp1 = 0
	temp2 = 1
	while temp1 < 10
		SpriteFrame(0, 0, 5, 5, temp2, 269) 
		temp1++
		temp2 += 5
	loop

	// 181-204 achievements
	temp0 = 0
	temp2 = 1
	temp3 = 342
	while temp0 < 4
		temp1 = 0
		while temp1 < 6
			SpriteFrame(0, 0, 50, 35, temp2, temp3) 
			temp1++
			temp2 += 51
		loop
		temp2 = 1
		temp0++
		temp3 += 36
	loop
	SpriteFrame(0, 0, 1, 6, 52, 269) // 205 . 
	SpriteFrame(0, 0, 1, 6, 54, 269) // 206 , 
	SpriteFrame(0, 0, 1, 6, 56, 269) // 207 ' 
	SpriteFrame(0, 0, 1, 6, 58, 269) // 208 ! 
	SpriteFrame(-68, -7, 136, 14, 118, 503) // 209 Sonic Forever

	temp1 = 0
	temp2 = 266
	while temp1 < 10
		SpriteFrame(0, 0, 15, 12, temp2, 268) // 210-219
		temp1++
		temp2 += 16
	loop
	SpriteFrame(0, 0, 15, 12, 234, 281) // 220
	SpriteFrame(0, 0, 15, 12, 250, 281) // 221

	SpriteFrame(-62, -24, 123, 48, 390, 484) // 222
	SpriteFrame(-62, -24, 123, 48, 390, 533) // 223
	SpriteFrame(0, 0, 15, 12, 286, 242) // 224 ,
	SpriteFrame(0, 0, 15, 12, 302, 242) // 225 ?
	SpriteFrame(0, 0, 15, 12, 234, 281) // 226 '

	SpriteFrame(-12, -10, 24, 24, 249, 475) // 227
	SpriteFrame(-12, -12, 24, 24, 224, 475) // 228

	SpriteFrame(-47, -3, 14, 20, 63, 298) // 229
	SpriteFrame(34, -3, 14, 20, 63, 319) // 230

	temp0 = 0
	while temp0 < 256
		GetPaletteEntry(1, temp0, temp1)			
		temp2 = temp1
		temp2 &= 0xE00000
		temp2 >>= 21
		switch saved.graphics
		case 0
			switch temp2
				case 0
					temp2 = 0
					break
				case 1
					temp2 = 8
					break
				case 2
					temp2 = 16
					break
				case 3
					temp2 = 32
					break
				case 4
					temp2 = 64
					break
				case 5
					temp2 = 96
					break
				case 6
					temp2 = 128
					break
				case 7
					temp2 = 160
					break
			end switch
			break
		case 1	
			switch temp2
				case 0
					temp2 = 0
					break
				case 1
					temp2 = 9
					break
				case 2
					temp2 = 18
					break
				case 3
					temp2 = 36
					break
				case 4
					temp2 = 72
					break
				case 5
					temp2 = 108
					break
				case 6
					temp2 = 144
					break
				case 7
					temp2 = 180
					break
			end switch	
			break
		case 2	
			switch temp2
				case 0
					temp2 = 0
					break
				case 1	
					temp2 = 13
					break	
				case 2
					temp2 = 26
					break	
				case 3
					temp2 = 52
					break
				case 4
					temp2 = 87
					break
				case 5
					temp2 = 116
					break
				case 6
					temp2 = 144
					break
				case 7
					temp2 = 172
					break
			end switch
			break
		end switch	
		temp3 = temp2
		temp3 <<= 16				
		
		temp4 = temp2
		temp4 <<= 8
		
		temp5 = temp2	

		temp1 = temp3
		temp1 += temp4
		temp1 += temp5
		SetPaletteEntry(2, temp0, temp1)
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
